Completed
Push — master ( e1ba59...cb8392 )
by Dimas
07:55
created

index.js ➔ loadDT   B

Complexity

Conditions 5

Size

Total Lines 51
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 37
c 0
b 0
f 0
dl 0
loc 51
rs 8.5253

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var table;
2
$(document).ready(function () {
3
  load_module(
4
    [
5
      "datatables.net",
6
      "datatables.net-bs4",
7
      "datatables.net-colreorder",
8
      "datatables.net-rowreorder",
9
      "datatables.net-scroller",
10
      "datatables.net-select",
11
      "datatables.net-buttons",
12
      "datatables.net-buttons-html5",
13
    ],
14
    function () {
15
      loadCSS([
16
        "https://adminlte.io/themes/v3/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css",
17
        "https://adminlte.io/themes/v3/plugins/datatables-responsive/css/responsive.bootstrap4.min.css",
18
      ]);
19
      datatables_init().then(loadDT);
20
    }
21
  );
22
});
23
24
function loadDT() {
25
  table = $("#list").DataTable({
26
    destroy: true,
27
    //dom: "Bfrtip",
28
    processing: false,
29
    serverSide: false,
30
    stateSave: false,
31
    autoWidth: false,
32
    responsive: true,
33
    deferRender: true,
34
    paging: true,
35
    lengthMenu: [5, 10, 15, 20, 25, 30, 100, 200, 300, 400, 500, "All"],
36
    ajax: {
37
      url: "list",
38
      method: "POST",
39
      data: {
40
        "list-user": guid(),
41
      },
42
      dataSrc: function (res) {
43
        console.log(res);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
44
45
        return res;
46
      },
47
    },
48
    columns: [
49
      {
50
        title: "username",
51
        data: "username",
52
      },
53
      {
54
        title: "name",
55
        data: "display_name",
56
      },
57
      {
58
        title: "email",
59
        data: "email",
60
      },
61
      {
62
        title: "Role",
63
        data: "role",
64
      },
65
      {
66
        title: "Last seen",
67
        data: "last_seen",
68
      },
69
    ],
70
  });
71
  table.on("init.dt", function () {
72
    $(this).removeClass("table-loader").show();
73
  });
74
}
75